package xyz.xuminghai.javafx_learn.scene.control;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * 2023/5/17 17:15 星期三<br/>
 * 超链接
 * 单击/按下超链接时， isVisited变为true 。 Hyperlink 的行为就像Button一样
 *
 * @author xuMingHai
 */
public class HyperlinkApp extends Application {

    private final AnchorPane anchorPane = new AnchorPane();

    private final HostServices hostServices = super.getHostServices();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Hyperlink hyperlink = new Hyperlink("www.baidu.com");
        hyperlink.setOnAction(event -> {
            String uri = hyperlink.getText();
            System.out.println("hyperlink = " + hyperlink.getText());
            hostServices.showDocument(uri);
        });

        anchorPane.getChildren().add(hyperlink);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(anchorPane, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
